<template>
	<el-main class="bg edit_wrap">
		<el-form ref="form" :model="form" status-icon label-width="120px" v-if="is_view()">
			<el-col v-if="user_group === '管理员' || $check_field('get','dormitory_building_id') || $check_field('add','dormitory_building_id') || $check_field('set','dormitory_building_id')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="宿舍楼" prop="dormitory_building_id">
					<el-input id="dormitory_building_id" v-model="form['dormitory_building_id']" placeholder="请输入宿舍楼id"
							  v-if="user_group === '管理员' || (form['dormitory_information_id'] && $check_field('set','dormitory_building_id')) || (!form['dormitory_information_id'] && $check_field('add','dormitory_building_id'))" :disabled="disabledObj['dormitory_building_id_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','dormitory_building_id')">{{form['dormitory_building_id']}}</div>
				</el-form-item>
			</el-col>
			<el-col v-if="user_group === '管理员' || $check_field('get','dormitory_id') || $check_field('add','dormitory_id') || $check_field('set','dormitory_id')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="宿舍" prop="dormitory_id">
					<el-input id="dormitory_id" v-model="form['dormitory_id']" placeholder="请输入宿舍id"
							  v-if="user_group === '管理员' || (form['dormitory_information_id'] && $check_field('set','dormitory_id')) || (!form['dormitory_information_id'] && $check_field('add','dormitory_id'))" :disabled="disabledObj['dormitory_id_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','dormitory_id')">{{form['dormitory_id']}}</div>
				</el-form-item>
			</el-col>
			<el-col v-if="user_group === '管理员' || $check_field('get','number_of_dormitories') || $check_field('add','number_of_dormitories') || $check_field('set','number_of_dormitories')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="宿舍人数" prop="number_of_dormitories">
					<el-input id="number_of_dormitories" v-model="form['number_of_dormitories']" placeholder="请输入宿舍人数"
							  v-if="user_group === '管理员' || (form['dormitory_information_id'] && $check_field('set','number_of_dormitories')) || (!form['dormitory_information_id'] && $check_field('add','number_of_dormitories'))" :disabled="disabledObj['number_of_dormitories_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','number_of_dormitories')">{{form['number_of_dormitories']}}</div>
				</el-form-item>
			</el-col>
			<el-col v-if="user_group === '管理员' || $check_field('get','dormitory_name') || $check_field('add','dormitory_name') || $check_field('set','dormitory_name')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="宿管名称" prop="dormitory_name">
					<el-input id="dormitory_name" v-model="form['dormitory_name']" placeholder="请输入宿管名称"
							  v-if="user_group === '管理员' || (form['dormitory_information_id'] && $check_field('set','dormitory_name')) || (!form['dormitory_information_id'] && $check_field('add','dormitory_name'))" :disabled="disabledObj['dormitory_name_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','dormitory_name')">{{form['dormitory_name']}}</div>
				</el-form-item>
			</el-col>
			<el-col v-if="user_group === '管理员' || $check_field('get','dormitory_remarks') || $check_field('add','dormitory_remarks') || $check_field('set','dormitory_remarks')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="宿舍备注" prop="dormitory_remarks">
					<el-input id="dormitory_remarks" v-model="form['dormitory_remarks']" placeholder="请输入宿舍备注"
							  v-if="user_group === '管理员' || (form['dormitory_information_id'] && $check_field('set','dormitory_remarks')) || (!form['dormitory_information_id'] && $check_field('add','dormitory_remarks'))" :disabled="disabledObj['dormitory_remarks_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','dormitory_remarks')">{{form['dormitory_remarks']}}</div>
				</el-form-item>
			</el-col>
			<el-col v-if="user_group === '管理员' || $check_field('get','student_name') || $check_field('add','student_name') || $check_field('set','student_name')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
				<el-form-item label="学生名称" prop="student_name">
					<el-input type="textarea" id="student_name" v-model="form['student_name']" placeholder="请输入学生名称"
						v-if="user_group === '管理员' || (form['dormitory_information_id'] && $check_field('set','student_name')) || (!form['dormitory_information_id'] && $check_field('add','student_name'))" :disabled="disabledObj['student_name_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','student_name')">{{form['student_name']}}</div>
				</el-form-item>
			</el-col>
			<el-col :xs="24" :sm="12" :lg="8" class="el_form_btn_warp">
				<el-form-item>
					<el-button type="primary" @click="submit()">提交</el-button>
					<el-button @click="cancel()">取消</el-button>
				</el-form-item>
			</el-col>

		</el-form>
	</el-main>
</template>

<script>
	import mixin from "@/mixins/page.js";

	export default {
		mixins: [mixin],
		data() {
			return {
				field: "dormitory_information_id",
				url_add: "~/api/dormitory_information/add?",
				url_set: "~/api/dormitory_information/set?",
				url_get_obj: "~/api/dormitory_information/get_obj?",
				url_upload: "~/api/dormitory_information/upload?",

				query: {
					"dormitory_information_id": 0,
				},

				form: {
					"dormitory_building_id":'', // 宿舍楼id
					"dormitory_id":'', // 宿舍id
					"number_of_dormitories":'', // 宿舍人数
					"dormitory_name":'', // 宿管名称
					"dormitory_remarks":'', // 宿舍备注
					"student_name":'', // 学生名称
					"dormitory_information_id": 0, // ID

				},
				disabledObj:{
					"dormitory_building_id_isDisabled": false,
					"dormitory_id_isDisabled": false,
					"number_of_dormitories_isDisabled": false,
					"dormitory_name_isDisabled": false,
					"dormitory_remarks_isDisabled": false,
					"student_name_isDisabled": false,
				},
			}
		},
		methods: {

			/**
			 * 获取对象之前
			 * @param {Object} param
			 */
			get_obj_before(param) {
				var form = "";
				if(this.form && form){
					Object.keys(this.form).forEach(key => {
						Object.keys(form).forEach(dbKey => {
							// if(dbKey === "charging_standard"){
							// 	this.form['charging_rules'] = form[dbKey];
							// 	this.disabledObj['charging_rules_isDisabled'] = true;
							// };
							if(key === dbKey){
								this.disabledObj[key+'_isDisabled'] = true;
							}
						})
					})
				}
				$.db.del("form");
				return param;
			},

			/**
			 * 获取对象之后
			 * @param {Object} json
			 * @param {Object} func
			 */
			get_obj_after(json, func){
			},

			is_view(){
				var bl = this.user_group == "管理员";

				if(!bl){
					bl = this.$check_action('/dormitory_information/table','add');
					console.log(bl ? "你有表格添加权限视作有添加权限" : "你没有表格添加权限");
				}
				if(!bl){
					bl = this.$check_action('/dormitory_information/table','set');
					console.log(bl ? "你有表格添加权限视作有修改权限" : "你没有表格修改权限");
				}
				if(!bl){
					bl = this.$check_action('/dormitory_information/view','add');
					console.log(bl ? "你有视图添加权限视作有添加权限" : "你没有视图添加权限");
				}
				if(!bl){
					bl = this.$check_action('/dormitory_information/view','set');
					console.log(bl ? "你有视图修改权限视作有修改权限" : "你没有视图修改权限");
				}
				if(!bl){
					bl = this.$check_action('/dormitory_information/view','get');
					console.log(bl ? "你有视图查询权限视作有查询权限" : "你没有视图查询权限");
				}

				console.log(bl ? "具有当前页面的查看权，请注意这不代表你有字段的查看权" : "无权查看当前页，请注意即便有字段查询权限没有页面查询权限也不行");

				return bl;
			},
			/**
			 * 上传文件
			 * @param {Object} param
			 */
			uploadimg(param) {
				this.uploadFile(param.file, "avatar");
			},

		},
		created() {
		},
	}
</script>

<style>
	.avatar-uploader .el-upload {
		border: 1px dashed #d9d9d9;
		border-radius: 6px;
		cursor: pointer;
		position: relative;
		overflow: hidden;
	}

	.avatar-uploader .el-upload:hover {
		border-color: #409EFF;
	}

	.avatar-uploader-icon {
		font-size: 28px;
		color: #8c939d;
		width: 178px;
		height: 178px;
		line-height: 178px;
		text-align: center;
	}

	.avatar {
		width: 178px;
		height: 178px;
		display: block;
	}
</style>
